package com.fzy.leetcodeExam.test352;

import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        Main test = new Main();
        System.out.println(test.maximumJumps(new int[]{0,2,1,3}, 1));

    }

    public int theMaximumAchievableX(int num, int t) {
        return num+2*t;
    }


    public int maximumJumps(int[] nums, int target) {
        int n = nums.length;
        int[][] dp  = new int[n][n];

        for(int i = 1;i<n;i++){
            if(nums[i] - nums[0] >= -target && nums[i]-nums[0] <=target){
                dp[0][i] = 1;
            }
        }

        for(int i = 1;i<n;i++){
            dp[i][i] = dp[i-1][i];
            for(int j = i+1;j<n;j++){
                int val = nums[j]-nums[i];
                if(val >= -target && val <= target){
                    dp[i][j] = dp[i][i] + 1;
                }else {
                    dp[i][j] = dp[i][i];
                }
            }
        }

        int ans = 0;
        for(int i = 0;i<n-1;i++){
            ans = Math.max(dp[i][n-1],ans);
        }

        return ans == 0 ? -1 : ans;
    }

}
